let app = getApp()

Page({
  data: {
    paihao: null,
    num: -1,
  },
  onShow() {
    var that = this;
    //如果openid不存在，就重新请求接口获取openid
    var openid = app.globalData.openid;
    if (openid === null || openid === undefined) {
      app.getOpenid();
      wx.showToast({ //这里提示失败原因
        title: 'openid为空！',
        duration: 1500
      })
      return;
    }
    wx.request({
      url: app.globalData.baseUrl + '/paihao/getNum',
      method: "GET",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        openid: openid
      },
      success(res) {
        console.log("查询排号成功", res)
        if (res && res.data && res.data.data) {
          let bean = res.data.data
          that.setData({
            paihaoSmall: bean.paihaoSmall,
            paihaoBig: bean.paihaoBig,
            paihao: bean.paihao
          })
        }
      },
      fail(res) {
        console.log("查询排号失败", res)
      }
    })
  },
  //点击了排号
  paihao: function (event) {
    //type  0小桌，1大桌
    let type = event.currentTarget.dataset.type
    var that = this;
    //如果openid不存在，就重新请求接口获取openid
    var openid = app.globalData.openid;
    if (openid === null || openid === undefined) {
      app.getOpenid();
      wx.showToast({ //这里提示失败原因
        title: 'openid为空！',
        duration: 1500
      })
      return;
    }
    wx.request({
      url: app.globalData.baseUrl + '/paihao/quhao',
      method: "GET",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        openid: openid,
        type: type
      },
      success(res) {
        console.log("排号成功", res)
        if (res && res.data && res.data.data) {
          wx.showToast({
            title: '排号成功',
          })
        }
      },
      fail(res) {
        console.log("排号失败", res)
      }
    })

  },
})